package com.boot.main.config.configDemo;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//控制反转
@Configuration
public class IocDemo {
    @Bean("tool")
    public Tool init(){
        return new Tool();
    }

    public class TestDemo{
        public void main(String[] args){
            ApplicationContext applicationContext = new AnnotationConfigApplicationContext(IocDemo.class);
            Tool tool = (Tool) applicationContext.getBean("tool");
            tool.print();
        }
    }
    public class Tool{
        public void print(){
            System.out.println("hello world");
        }
    }
}

